﻿using System;
using System.Collections.Generic; 
using System.Text;
using ATSModel;
using ATSIDAL;
using System.Data.SqlClient;
using DBUtility;
using System.Data;

namespace ATSDAL
{ 
    public class AllStatusDal : BaseRepository_DT<AllStatusInfo>, IAllStatus
    {

        #region 静态变量定义部分
        private const string PARM_PRODUCTTYPEID = "@ProductSN"; 
        private const string PARM_RECORDTIME = "@Time"; 
        #endregion

        //-------------------------------------用于标签打印软件上传数据录入的Web Service-----------------------------------------------------
       
        /// <summary>
        /// 根据SN 查询测试结果
        /// </summary>
        /// <param name="productSN"></param>
        /// <returns></returns>
        ///（标签打印软件对接） 
        public IList<AllStatusInfo> EleResult_AllStatus_GetbySN(string productSN)
        {
            SqlParameter parm = GetParameter(PARM_PRODUCTTYPEID);
            parm.Value = productSN;
            IList<AllStatusInfo> AList = new List<AllStatusInfo>();
            using (SqlDataReader rdr = sqlHelper.ExecuteReader(sqlHelper.ConnectionStringLocalTransaction, CommandType.StoredProcedure, "sp_selAllStatusbySN", parm))
            {
                while (rdr.Read())
                {
                    AllStatusInfo Entity = new AllStatusInfo();
                    Entity.Id = rdr.GetInt32(0);
                    Entity.ProductSN = rdr.GetValue(1).ToString();
                    Entity.Status = rdr.GetValue(2).ToString();
                    Entity.Time = Convert.ToDateTime(rdr.GetValue(3));
                    Entity.Remark1 = rdr.GetValue(4).ToString();
                    Entity.Remark2 = rdr.GetValue(5).ToString();
                    Entity.Remark3 = rdr.GetValue(6).ToString();
                    AList.Add(Entity);
                }
            }

            return AList;
        }




        #region 重写重用基类部分
        //-------------------------------------重写超类基础操作---------------------------------------------------------

        public override AllStatusInfo GetEntityRecord(SqlDataReader rdr)
        {
            AllStatusInfo aro = new AllStatusInfo
            {
                Id = rdr.GetInt32(0),
                ProductSN = rdr.GetValue(1).ToString(),
                Status = rdr.GetValue(2).ToString(),
                Time = rdr.GetDateTime(3),
                Remark1 = rdr.GetValue(4).ToString(),
                Remark2 = rdr.GetValue(5).ToString(),
                Remark3 = rdr.GetValue(6).ToString() 
            };
            return aro;
        }

        private static SqlParameter GetParameter(string parmname)
        {
            SqlParameter parm = new SqlParameter(parmname, SqlDbType.NVarChar, 50);
            return parm;
        }
 
        #endregion


        #region IBaseRepository<PrintRecordInfo> 成员


        public AllStatusInfo LoadEntity<T1>(T1 Id)
        {
            throw new NotImplementedException();
        }

        public IList<AllStatusInfo> LoadEntities()
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
